package com.hinata.hinataimageloader;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hinata.hinataimageloader.RecyclerViewHoder;


import java.util.List;

/**
 * Created by Hinata on 2017/4/15.
 */

public class GalleryAdapter extends RecyclerView.Adapter<RecyclerViewHoder>{


    private LayoutInflater mInflater;
    private List<Integer> mDatas;
    private RecyclerViewItemClickListener mItemClickListener;

    public GalleryAdapter(Context context, List<Integer> datats)
    {
        mInflater = LayoutInflater.from(context);
        mDatas = datats;
    }



    @Override
    public int getItemCount()
    {
        return mDatas.size();
    }

    /**
     * 创建ViewHolder
     */
    @Override
    public RecyclerViewHoder onCreateViewHolder(ViewGroup viewGroup, int i)
    {
        View view = mInflater.inflate(R.layout.item_image, viewGroup, false);
        RecyclerViewHoder viewHolder = new RecyclerViewHoder(view,mItemClickListener);
        return viewHolder;
    }

    /**
     * 设置值
     */
    @Override
    public void onBindViewHolder(final RecyclerViewHoder viewHolder, final int i)
    {
        viewHolder.iv.setImageResource(mDatas.get(i));
    }

    /**
     *
     * @param listener
     */

    public void setOnItemClickListener(RecyclerViewItemClickListener listener){
        this.mItemClickListener=listener;

    }

}
